﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ODataRegression.Framework.Core.TestOM;
using ODataRegression.Framework.Core.MetaDataOM;
using ODataRegression.Framework.Core.Shared;
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Xml;
using ODataTestFrameworkCore.shared;

namespace ODataRegression.Framework.Core.Factories
{
    public class ODataOrderByTestFactory : ODataTestFactoryBase
    {

        public override List<ODataTest> CreateTestList()
        {
            if (this.ISAvtiveTest)
            {
                maxTestGenerationCount = GetMaxTestGenerationCount();
                string columnList = string.Empty;

                foreach (ODataEntityProperty item in entitySet.Entity.Properties)
                {
                    FinalQueryURL = QueryURLBase + item.Name + "&$top=1";
                    FinalQueryURL = URLMappers.ApplyConfigMappingActions(FinalQueryURL);

                    if (item.Type != "Edm.Binary" && (item.Type != "Edm.String"))
                    {
                        base.CreateTestList();
                        generatedTestCount++;
                        if (generatedTestCount >= maxTestGenerationCount)
                        {
                            break;
                        }


                    }



                }

                string propertyList = entitySet.Entity.GetSupportedPropertyList(this.testName);
                ////Do not create test if there is only one prop has been returned because it has already been tested above
                if (propertyList != null && propertyList.Split(',').Length > 1)
                {
                    FinalQueryURL = QueryURLBase + propertyList + "&$top=1";
                    FinalQueryURL = URLMappers.ApplyConfigMappingActions(FinalQueryURL);
                    base.CreateTestList();
                }

            }
            // Generate a select query with all columns 

            return testList;
        }

        public ODataOrderByTestFactory(string serviceRoot, string ServiceName, ODataEntitySet entityset)
            : base(serviceRoot, ServiceName, entityset)
        {

            EntityBaseURL = entitySet.URL;
            QueryURLBase = EntityBaseURL + "?$orderby=";
            testName = ODataTestNames.OrderBy;
            testTile = "Verify that $orderby is working for selected entity";
        }
    }
}
